package com.chukun.multi.masterslave;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author chukun
 * 流量统计工具 java模块代码
 */
public class TPSStatExample {
    public static void main(String[] args) throws IOException {
        // 接口日志文件所在的目录
        String logBaseDir = args[0];
        // 忽略的操作名列表
        String excludedOperationNames = "";

        // 指定要统计在内的目标设备名
        String includedOperationNames = "*";

        // 指定要统计在内的目标设备名
        String destinationSysName = "*";

        int argc = args.length;
        if (argc > 2) {
            excludedOperationNames = args[1];
        }
        if (argc > 3) {
            includedOperationNames = args[2];
        }
        if (argc > 4) {
            destinationSysName = args[3];
        }
        // 创建master，分发任务
        Master.Builder builder = new Master.Builder();
        builder.setLogFileBaseDir(logBaseDir)
                .setIncludedOperationNames(includedOperationNames)
                .setExcludedOperationNames(excludedOperationNames)
                .setDestinationSysName(destinationSysName);
        Master processor = new Master(builder);

        BufferedReader fileNamesReader = new BufferedReader(new InputStreamReader(System.in));
        // 任务分发
        Map<String, AtomicInteger> resultMap = processor.calculate(fileNamesReader);
        resultMap.forEach((k, v) -> {
            System.out.println(k + " , " + resultMap.get(k));
        });
    }
}
